
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "tlg_png.h"

int main(int argc, char *argv[])
{
	if (argc == 3)
	{
		if (tlg_file_to_png_file(argv[1], argv[2]))
		{
			fprintf(stderr, "Failed to convert TLG to PNG\n");
			return -1;
		}
		else
		{
			return 0;
		}
	}
	else if (argc == 2)
	{
		char* png = strdup(argv[1]);
		int n = strlen(png);
		if (n <= 4 || png[n-4] != '.' || (png[n-3] != 't' && png[n-3] != 'T') || (png[n-2] != 'l' && png[n-2] != 'L') || (png[n-1] != 'g' && png[n-1] != 'G'))
		{
			fprintf(stderr, "%s is not .tlg\n", png);
			return -1;
		}
		png[n-3] = 'p';
		png[n-2] = 'n';
		png[n-1] = 'g';
		if (tlg_file_to_png_file(argv[1], png))
		{
			fprintf(stderr, "Failed to convert TLG to PNG\n");
			free(png);
			return -1;
		}
		else
		{
			free(png);
			return 0;
		}
	}
	else
	{
		fprintf(stderr, "tlg2png tlg_path png_path\n");
		//tlg_file_to_png_file("5.tlg", "5.png");
		return -1;
	}
}

